import {findAllType, findPage} from '@/api/sales/salesOutbound'
import pickerOptions from '@/utils/date';
import outBound from "@/components/index.vue";

export default {
    components: {
        outBound,
    },
    data() {
        return {
            pickerOptions,
            tableData: [],
            id: 0,
            total: 0,
            batchIds: [],
            searchParams: {currentPage: 1, pageSize: 10},
            dialogFormVisible: false,
            formData: {},
            imageUrl: '',
            options: [],
            value: '',
            dialogVisible:false,

        };
    },
    methods: {
        // //接收子页面传过来的值
        // childByValue: function (childValue) {
        //     this.dialogTableVisible = false;
        //     // childValue就是子组件传过来的值
        //     this.merchEntity = childValue;
        // },
        load(tree, treeNode, resolve) {
            setTimeout(() => {
                resolve([
                    {
                        id: 31,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }, {
                        id: 32,
                        date: '2016-05-01',
                        name: '王小虎',
                        address: '上海市普陀区金沙江路 1519 弄'
                    }
                ])
            }, 1000)
        },
        clickParent() {
            this.$refs.www;
        },
        openBuy(){
            // this.$nextTick(()=>{
                // this.$refs.order
            // })
            this.dialogVisible = true;
        },
        selectChange(brandList) {
            if (brandList.length == 1) {
                this.formData.id = brandList[0].id;
            }
            this.batchIds = brandList.map(item => item.id);
            // console.log(brandList);
            // brandList.map(item =>{
            //     console.log(item.orderStatus);
            //     return item.orderStatus === "待出库";
            // })
        },
        selectTable(row){
            return row.orderStatus === "已出库";
        },
        async searchPage() {
            let response = await findPage(this.searchParams);
            this.tableData = response.data;
            console.log(this.tableData)
            this.total = response.total;
        },
        chooseTime() {
            this.searchParams.startTime = this.pickerOptions.startDate[0];
            this.searchParams.endTime = this.pickerOptions.startDate[1];
        },
        currentPageChange(currentIndex) {
            this.searchParams.currentPage = currentIndex;
            this.searchPage();
        },
        resetForm() {
            this.searchParams = {currentPage: 1, pageSize: 5}
            this.pickerOptions.startDate = '';
            this.searchPage()
        },

        lookOrder(id) {
            this.$router.push({
                path: `/lookOrder/${id}`,
            })
        },
        async findAllType() {
            this.options = await findAllType();
        },
        createBatchExcel() {
            if (this.batchIds.length){
                window.location.href = "http://localhost:8088/stockOut/createBatchExcel/" + this.batchIds;
            }else {
                this.$notify.error({
                    title: '错误',
                    message: '选都没选下个寂寞?'
                });
            }

        },


    },
    created() {
        this.searchPage()
        this.findAllType()
    }
};
